#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;
#define maxn 10001
#define maxm 50001
#define maxb 1000000001
const int INF = 1<<30;
const int eps = 1;

int n,V,life;
vector<pair<int, int> > G[maxn];
int fee[maxn];
int dis[maxn];
bool visited[maxn];

void SPFA(int s, int limit) {
    for (int i = 0; i <= n; i++) dis[i] = INF;
    queue<int> que;
    dis[s] = 0;
    visited[s] = true;
    que.push(s);
    int u;
    while (!que.empty()) {
        u = que.front(); que.pop();
        visited[u] = false;
        for (int i=0;i<G[u].size();i++) {
			auto son = G[u][i];
            int v = son.first;
            int w = son.second;
            if (dis[v] > dis[u] + w && fee[v] <= limit) {
                dis[v] = dis[u] + w;
                if (!visited[v]) {
                    que.push(v);
                    visited[v] = true;
                }
            }
        }
    }
}

bool check(int limit){
	SPFA(1, limit);
	if(dis[n]<life) return true;
	else return false;
}

int main(){
    cin>>n>>V>>life;
	for(int i=1; i<=n; i++)
		cin>>fee[i];
    for(int i=0; i<V; i++){
        int u,v,w;
        cin>>u>>v>>w;
        G[u].push_back(make_pair(v, w));
		G[v].push_back(make_pair(u, w));
    }

    int l=1, r=1<<30, mid;
	while(r-l>eps){
		mid=(l+r)/2;
		if(check(mid)) r=mid;
		else l=mid;
	}

	if(l<INF-1) cout<<r<<endl;
	else cout<<"AFK"<<endl;

    return 0;
}